﻿using System.Linq;
using System.Reflection;
using BusinessLogic.BusinessEntity.Interfaces;
using NUnit.Framework;

namespace Common.Tests
{
	public static class PropertyAssertion
	{
		public static void AssertProperties<T>(T expected, T actual)
		{
			PropertyInfo[] properties = typeof(T).GetProperties();

			foreach (PropertyInfo property in properties)
			{
				if (property.PropertyType == typeof(string) ||
					property.PropertyType == typeof(int) ||
					property.PropertyType == typeof(decimal))
				{
					object expectedValue = property.GetValue(expected, null);
					object actualValue = property.GetValue(actual, null);

					Assert.That(expectedValue, Is.EqualTo(actualValue));
				}

				if(property.PropertyType.GetInterfaces().ToList().Contains(typeof(IIdentifiedEntity)))
				{
					int expectedValue = ((IIdentifiedEntity) property.GetValue(expected, null)).ID;
					int actualValue = ((IIdentifiedEntity) property.GetValue(actual, null)).ID;

					Assert.That(expectedValue, Is.EqualTo(actualValue));
				}
			}
		}
	}
}
